﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tetris
{
    public class InputHandler
    {
        public event EventHandler SpeedUp;
        public event EventHandler SpeedDown;
        public event EventHandler RotateShape;
        public event EventHandler MoveShapeRight;
        public event EventHandler MoveShapeLeft;

        public void QueryKeyBoard()
        {
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo kInfo = Console.ReadKey(true);

                switch (kInfo.Key)
                {
                    case ConsoleKey.Add:
                    case ConsoleKey.DownArrow:
                        OnSpeedUp();
                        break;
                    case ConsoleKey.OemMinus:
                    case ConsoleKey.Subtract:
                        OnSpeedDown();
                        break;
                    case ConsoleKey.Spacebar:
                        OnRotateShape();
                        break;
                    case ConsoleKey.RightArrow:
                        OnMoveRight();
                        break;
                    case ConsoleKey.LeftArrow:
                        OnMoveLeft();
                        break;



                }
            }
        }

        protected virtual void OnSpeedUp()
        {
            if (this.SpeedUp != null)
                this.SpeedUp(this, EventArgs.Empty);
        }

        protected virtual void OnSpeedDown()
        {
            if (this.SpeedDown != null)
                this.SpeedDown(this, EventArgs.Empty);
        }
        protected virtual void OnRotateShape()
        {
            if (this.RotateShape != null)
                this.RotateShape(this, EventArgs.Empty);
        }
        protected virtual void OnMoveRight()
        {
            if (this.MoveShapeRight != null)
                this.MoveShapeRight(this, EventArgs.Empty);
        }
        protected virtual void OnMoveLeft()
        {
            if (this.MoveShapeLeft != null)
                this.MoveShapeLeft(this, EventArgs.Empty);
        }

    }
}
